<%-- 
 *Workshop 
 *Class ID        : SE0691   
 *Student ID      : SE90009
 *Student Name    : Phạm Nguyễn Nhật Trung
 *Due Date        : Nov 22, 2012, 6:02:22 PM
 *I declare that this assignment is my own work
 *in accordance with FPT Policy.
--%>

<%@page import="java.util.Iterator"%>
<%@page import="java.util.Collection"%>
<%@page import="tracker.Torrents"%>
<%@page import="tracker.TrackerHelper"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="Trackertag" uri="/WEB-INF/tlds/TrackerTag_library" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <LINK REL=StyleSheet HREF="../style/style.css" TYPE="text/css" MEDIA=screen>
        <title>Search Page</title>
    </head>
    <body>
        <%
            Boolean isLogin = false;
            Cookie[] ck = request.getCookies();
            if (ck != null) {
                for (int i = 0; i < ck.length; i++) {
                    if ("userId".equals(ck[i].getName())) { //Finding Username Cookie                
                        i = ck.length;
                        isLogin = true;
                    }
                }

            }
            if (isLogin == false) {
                response.sendRedirect("login.jsp");
                return;
            }
        %>
        <jsp:include page="navigation.jsp" />
        <div class="center-form" style="padding-top: 50px; margin-bottom: -15px;">
            <Form id="tracker-login-form" action ='' method='post'>
                <input type="text" name="data" value="" style=" height: 32px;"/>
                <input class="bg-color-yellow" type="submit" value="Search" name="searchSubmit" style="margin-top:5px;"/>
            </Form>
        </div>
        <div id="torrent-list-form">
            <%
                String data = "";
                response.setContentType("text/html;charset=UTF-8");
                try {
                    /* TODO output your page here. You may use following sample code. */
                    if (request.getParameter("data") != null) {
                        try {
                            data = request.getParameter("data");
                        } catch (Exception e) {
                            out.println("<div style=\"width:800px; margin:0 auto; padding-top: 250px\"><h3>" + e.getMessage() + "</h3></div>");
                        }
                    }
                } catch (Exception e) {
                    out.println("<div style=\"width:800px; margin:0 auto; padding-top: 250px\"><h3>" + e.getMessage() + "</h3></div>");
                } finally {
                    //out.close();
                }
            %>
            <div style="padding-left: 10px;"><h2>Search Torrents & Users</h2></div>
            <ul id="holder">
                <Trackertag:searchTagHandler dataString="<%= data%>"/>
            </ul> 
        </div>
        <script type="text/javascript" src="../scripts/jquery.js"></script>
        <script type="text/javascript" src="../scripts/pagination.js"></script>
    </body>
</html>
